package com.kaiwukj.android.ufamily.mvp.ui.page.service.gm;

import android.content.Intent;
import android.net.Uri;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class GMProjectAnnexOtherAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    public GMProjectAnnexOtherAdapter(@Nullable List<String> data) {
        super(R.layout.item_gm_order_detail_annex_file, data);
        addChildClickViewIds(R.id.iv_download);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, String path) {
        holder.setText(R.id.tv_file_name, getNameByUrl(path));
        holder.getView(R.id.iv_download)
                .setOnClickListener(v -> {
                   /* DownloadUtils downloadUtils = new DownloadUtils(getContext());
                    downloadUtils.downloadFile(path, getNameByUrl(path));*/
                    getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(path)));
                });

        /**
         * ARouter.getInstance().build(ARouterUrlKt.GMFilePreviewUrl)
         *                     .withString("url", result.getDesignSketchUrl())
         *                     .navigation();
         */
    }

    private String getNameByUrl(String url) {
        int index = url.lastIndexOf("/");
        return url.substring(index + 1);
    }
}
